package com.example.demo2.generator.service.impl;

import com.example.demo2.generator.entity.PlanList;
import com.example.demo2.generator.mapper.PlanListDao;
import com.example.demo2.generator.service.PlanListService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;
import java.util.List;

/**
 * 计划列表(PlanList)表服务实现类
 *
 * @author makejava
 * @since 2024-09-26 15:07:07
 */
@Service("planListService")
public class PlanListServiceImpl implements PlanListService {
    @Resource
    private PlanListDao planListDao;

    /**
     * 查询所有计划列表
     */
    @Override
    public List<PlanList> planListAll() {
        return planListDao.planListAll();
    }

    /**
     * 通过ID查询单条数据
     *
     * @param planListId 主键
     * @return 实例对象
     */
    @Override
    public PlanList queryById(Integer planListId) {
        return this.planListDao.queryById(planListId);
    }

    /**
     * 分页查询
     *
     * @param planList 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<PlanList> queryByPage(PlanList planList, PageRequest pageRequest) {
        long total = this.planListDao.count(planList);
        return new PageImpl<>(this.planListDao.queryAllByLimit(planList, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param planList 实例对象
     * @return 实例对象
     */
    @Override
    public PlanList insert(PlanList planList) {
        this.planListDao.insert(planList);
        return planList;
    }

    /**
     * 修改数据
     *
     * @param planList 实例对象
     * @return 实例对象
     */
    @Override
    public PlanList update(PlanList planList) {
        this.planListDao.update(planList);
        return this.queryById(planList.getPlanListId());
    }
    /**
     * 通过主键删除数据
     *
     * @param planListId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer planListId) {
        return this.planListDao.deleteById(planListId) > 0;
    }

    @Override
    public int deletesById(List<PlanList> planList) {
        return planListDao.deletesById(planList);
    }

    @Override
    public List<PlanList> queryByLike(PlanList list) {
        return planListDao.queryByLike(list);
    }
}
